package com.bestcem.xm.ticket.controller.param.ticket.config.createParam;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.ticket.entity.mongo.TicketRule;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.List;

/**
 * @author zq.ding <zq.ding@idiaoyan.com>
 * @version v1.0
 * @date 2021/9/8 16:56
 */
@Data
public class ConditionParam implements Serializable {

    private static final long serialVersionUID = 4449032242996334029L;
    @JsonProperty(value = "logic")
    private Integer logic;

    @JsonProperty(value = "filters")
    private List<JSONObject> filters;

    @JsonProperty(value = "rtype")
    private Integer ruleType;

    @JsonProperty(value = "rule")
    private String rule;

    @Nullable
    public static TicketRule.Condition paramToEntity(ConditionParam param) {
        if (param == null) {
            return null;
        }
        TicketRule.Condition condition = new TicketRule.Condition();
        condition.setLogic(param.getLogic());
        condition.setFilters(param.getFilters());
        condition.setRuleType(param.getRuleType());
        condition.setRule(param.getRule());
        return condition;
    }
}
